// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from "vuex"
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import App from './App'
import routes from './router/index.js'
import { DevicePlugin, ToastPlugin, AlertPlugin, ConfirmPlugin, LoadingPlugin,AjaxPlugin ,WechatPlugin} from 'vux'
Vue.use(DevicePlugin)
Vue.use(ToastPlugin)
Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(LoadingPlugin)
// AjaxPlugin 和vue-resource一样在组件内使用this.$http进行调用了。
Vue.use(AjaxPlugin)
//微信js sdk
Vue.use(WechatPlugin)
Vue.use(Vuex)


// const vuxLocales = require('json!yaml!vux/src/locales/all.yml')
// const componentsLocales = require('json!yaml!src/locales/components.yml')
// const globalLocales = require('json!yaml!src/locales/global_locales.yml') || {en: {}, 'zh-CN': {}}

// const finalLocales = {
//   'en': objectAssign(vuxLocales['en'], componentsLocales['en'], globalLocales['en']),
//   'zh-CN': objectAssign(vuxLocales['zh-CN'], componentsLocales['zh-CN'], globalLocales['zh-CN'])
// }

// for (let i in finalLocales) {
//   Vue.i18n.add(i, finalLocales[i])
// }
// Vue.i18n.set('zh-CN')

const store = new Vuex.Store({}) // 这里你可能已经有其他 module

store.registerModule('vux', { // 名字自己定义
  state: {
    isLoading: false
  },
  mutations: {
    updateLoadingStatus (state, payload) {
       state.isLoading = payload.isLoading
    }
  }
})

routes.beforeEach(function (to, from, next) {
  store.commit('updateLoadingStatus', {isLoading: true})
  next()
})

routes.afterEach(function (to) {
  setTimeout(function() {
      store.commit('updateLoadingStatus', {isLoading: false})
    
  },500)
})


//点击延迟
FastClick.attach(document.body)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  router:routes,
  store,
  render: h => h(App)
}).$mount('#app-box')
